import zipfile
import os

class DetermineFunction:
    @staticmethod
    def PathisComic(path):
        if DetermineFunction.PathisBook(path):
            return False
        else:
            return True
    @staticmethod
    def PathisBook(path):
        if os.path.exists(path):
            if os.path.isdir(path):
                return DetermineFunction.FilelistisBook(os.listdir(path))                    
            elif os.path.isfile(path):
                return DetermineFunction.ZipFileisBook(path)
            else:
                return False
        else:
            return False
    @staticmethod
    def ZipFileisBook(zippath):        
        flist = zipfile.ZipFile(zippath, 'r').namelist()
        return DetermineFunction.FilelistisBook(flist)        
    @staticmethod
    def DirisBook(dirpath):
        flist = os.listdir(dirpath)
        return DetermineFunction.FilelistisBook(flist)    
    @staticmethod
    def FilelistisBook(filelist):
        list_len = len(filelist)
        image_len = DetermineFunction.getnumimagefile(filelist)
        
        if list_len < 0:
            return False
        
        if list_len*0.5 > image_len:
            return False
        
        return True
    @staticmethod
    def getnumimagefile(file_list):
        type_list = ['.jpg', '.jpeg', '.png', '.gif']
        reint = 0
        for ff in file_list:
            for tt in type_list:
                if ff.endswith(tt):
                    reint = reint + 1
                    break
        return reint